﻿using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;

namespace NewRetail.Application.Worker
{
    public class EnsureDatabaseCreatedWoker : ITransientDependency
    {
        private readonly IDataSeeder dataSeeder;
        private readonly ILogger logger;
        public EnsureDatabaseCreatedWoker(IDataSeeder dataSeeder, ILogger<EnsureDatabaseCreatedWoker> logger)
        {
            this.dataSeeder = dataSeeder;
            this.logger = logger;
        }

        public async Task Execute()
        {
            try
            {
                await this.dataSeeder.SeedAsync();
                this.logger.LogInformation("初始化数据库成功");
            }
            catch (Exception e)
            {
                this.logger.LogError(e, e.Message);
                throw;
            }
        }
    }
}
